package 高效制胜._01;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/9/7 9:01
 * 两数之和
 * 算法：哈希表
 */
public class _01 {

    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int expect = target - nums[i];
            if (map.containsKey(expect)) return new int[]{map.get(expect), i};
            map.put(nums[i], i);
        }
        return new int[0];
    }

}
